package com.haidong.string;

public class MoreApi {
    public static void main(String[] args) {
        //1.public int length();顾名思义,不演示
        //2.public char charAt(int index);根据索引返回字符,可用来实现遍历字符串
        String str1 = "qwertyuiop";
        System.out.println(str1.charAt(2));
        //3.public char[] toCharArray();转换成字符数组
        char[] str2 = str1.toCharArray();
        for (int i = 0; i < str2.length; i++) {
            System.out.println(str2[i]);
        }
        //4.public String substring(int beginIndex,int endIndex);截取内容,包前不包后
        String str3 = "这里的内容 截取的内容 留下";
        System.out.println('|' + str3.substring(6,11) + '|');
        //5.public String substring(int beginIndex);从当前位置直接截取到末尾
        System.out.println(str3.substring(6));
        //6.public String replace(CharSequence target,CharSequence replancement);
        String str4 = "老师,我是梁志超他奶奶,梁志超骂我大傻逼,我他妈七十多岁该他骂的?" +
                "老师啊,这孩子咋整吧,他爹妈不在家." +
                "我让他回来吃饭,他说我不吃能咋滴,我他妈就不吃能咋地,长得跟个小菜似的.";
        String str5 = str4.replace("他奶奶","***");
        String str6 = str5.replace("大傻逼","***");
        String str7 = str6.replace("他妈","**");
        String str8 = str7.replace("小菜","**");
        System.out.println(str8);
        //7.public boolean contains(String regex);判断regex字符串是否出现在字符串中
        if (str4.contains("他奶奶")) {
            System.out.println("他奶奶在str4里面");
        }
        //8.public boolean startsWith(String prefix);判断字符串是否以prefix开头
        if (str4.startsWith("老师")) {
            System.out.println("老师是str4的开头");
        }
        //9.public String[] split(String s);按照某个内容将字符串分割成字符串数组
        System.out.println(str4.split("老师")[1]);
    }
}
